package com.taotao.zerocopy;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Description: 传统IO操作，多次内存拷贝和上下文切换；
 * @Author: TaoJF
 * @Date: Created in 2018/7/8 下午3:32
 */
public class OldIOServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8088);
        System.out.println("服务器端启动监听...");
        while (true) {
            Socket socket = serverSocket.accept();
            System.out.println("监听到，进行处理...");
            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());

            byte[] byteArray = new byte[4069];
            int totalReadCount = 0;
            while (true) {
                int readCount = dataInputStream.read(byteArray, 0, byteArray.length);
                totalReadCount += readCount;
                if (-1 == readCount) {
                    break;
                }
            }
            System.out.println("读取到的字节长度：" + totalReadCount);
        }
    }

}
